package main

import "fmt"

type celsius float64
type f float64

type drawTempLine func(temp1 celsius, temp2 f, sign bool)

func (c celsius) cToF() f {
	return f(c*1.8 + 32.0)
}

func (f f) fToC() celsius {
	return celsius((f - 32.0) / 1.8)
}

func drawLine(num1 celsius, num2 f, sign bool) {
	if sign {
		fmt.Printf("|%-8v|%-8v|\n", num1, num2)
	} else {
		fmt.Printf("|%-8v|%-8v|\n", num2, num1)
	}
}

func drawDoubleLine() {
	fmt.Println("===================")
}

func drawTable(firstTemp string, drawLine drawTempLine) {
	var sign = true
	drawDoubleLine()
	if firstTemp == "celsius" {
		fmt.Println("|摄氏度  |华氏度  |")
	} else {
		sign = false
		fmt.Println("|华氏度  |摄氏度  |")
	}
	drawDoubleLine()

	for c := celsius(-40.0); c <= 100; c += 5 {
		drawLine(c, c.cToF(), sign)
	}

	drawDoubleLine()
}

func main() {
	drawTable("celsius", drawLine)
	drawTable("f", drawLine)
}
